/**
  ******************************************************************************
  * @file    main.cpp
  * @author  
  * @version V1.0
  * @date    2017-xx-xx
  * @brief   
  ******************************************************************************
  * @attention
  *
  *
  ******************************************************************************
  */

#include	"stdbool.h"
#include	"stm32f4xx.h"
#include	"bsp_led.h"	
#include	"delay.h"
#include	"bsp_key.h"
#include	"bsp_exit.h"
#include	"led_task.h"
#include	"key_task.h"
#include	"bsp_can.h"
#include	"can_task.h"

#include 	"FreeRTOS.h"
#include 	"task.h"
#include	"queue.h"

//RCC_ClocksTypeDef	RCC_Clocks;
TaskHandle_t xHandleTaskLed = NULL;
TaskHandle_t xHandleTaskKey = NULL;

xQueueHandle	xQueueCAN;

static void BspInit(void);

int	main()
{		
//  RCC_GetClocksFreq(&RCC_Clocks);
//  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);/* SysTick end of count event each 1ms */

	TaskHandle_t xHandleTaskCAN = NULL;

	cLED	led2(LED2_GPIO_PORT, LED2_PIN);
	cLED	led3(LED3_GPIO_PORT, LED3_PIN);
	
	BspInit();
	
	led2.Off();
	led3.Off();
	
	xQueueCAN = xQueueCreate(5, sizeof(CanRxMsg));
	
	xTaskCreate(vTaskLed, "TaskLed", 100, NULL, 1, &xHandleTaskLed);
	xTaskCreate(vTaskKey, "TaskKey", 100, NULL, 2, &xHandleTaskKey);
	xTaskCreate(vTaskCAN, "TaskCAN", 100, NULL, 3, &xHandleTaskCAN);
	
	vTaskStartScheduler();
	
//	while(1);
}

static void BspInit(void)
{
	NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
	
	LED_GPIO_Config();
	Key_GPIO_Config();
	EXTI_Key_Config();
	CAN_Config();
}

